package com.sinoglobal.sinostore.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.sinoglobal.sinostore.R;
/**
 * @author czz
 * @createdate 2014-9-11 下午2:20:10
 * @Description: TODO(辣椒圈商城 dilog风格1:大致分为三种风格 在使用时可以查看布局来选择适合自己的dialog)
 */
public class ShopDialogStyle2 extends Dialog implements android.view.View.OnClickListener {

	private ShopDialogStyle1Listener shopdialogstyle1;
	public TextView confirm;
	public TextView cancel;
	public TextView title;
	public TextView message;

	public void setCancelable(boolean cancelable) {
		this.setCanceledOnTouchOutside(cancelable);
	}
	public void setMyDialogListener(ShopDialogStyle1Listener myDialogListener) {
		this.shopdialogstyle1 = myDialogListener;
	}


	public ShopDialogStyle2(Context context) {
		super(context, R.style.alert_dialog);
		setContentView(R.layout.shop_dialogstyle2);
		init();
		showListener();
		if (context instanceof ShopDialogStyle1Listener) {
			shopdialogstyle1 = (ShopDialogStyle1Listener) context;
		}
		// windowDeploy(0, 0);
	}
	
	public ShopDialogStyle2(Context context,String str_title,String str_message,String str_confirm,String str_cancel){
		super(context, R.style.dialog);
		setContentView(R.layout.shop_dialogstyle2);
		init();
		showListener();
		if (context instanceof ShopDialogStyle1Listener) {
			shopdialogstyle1 = (ShopDialogStyle1Listener) context;
		}
		//如果标题为空隐藏原先标题 若不为空这设置标题
		if("".equals(str_title)){
			title.setVisibility(View.INVISIBLE);
		}else{
			title.setVisibility(View.VISIBLE);
			title.setText(str_title);
		}
		if("".equals(str_message)){
			message.setVisibility(View.INVISIBLE);
		}else{
			message.setVisibility(View.VISIBLE);
			message.setText(str_message);
		}
		confirm.setText(str_confirm);
		cancel.setText(str_cancel);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	public void init() {
		confirm = (TextView) findViewById(R.id.confirm);
		cancel = (TextView) findViewById(R.id.cancel);
		title = (TextView) findViewById(R.id.title);
		message = (TextView) findViewById(R.id.message);
	}

	public void showListener() {
		confirm.setOnClickListener(this);
		cancel.setOnClickListener(this);
	}

	public static interface ShopDialogStyle1Listener {
		void confirm(); //自取
		void cancel(); //快递到家
	}

	@Override
	public void onClick(View v) {
		cancel();
		int id = v.getId();
		if (id == R.id.confirm) {
			if (shopdialogstyle1!=null) {
				shopdialogstyle1.confirm();
			}
		} else if (id == R.id.cancel) {
			if (shopdialogstyle1!=null) {
			shopdialogstyle1.cancel();
			}
		} else {
		}
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		try {
			super.show();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}
